//
//  RegistViewController.m
//  MyBlog
//
//  Created by zhen7216 on 2017/5/25.
//  Copyright © 2017年 chenzhen. All rights reserved.
//

#import "RegistViewController.h"

@interface RegistViewController ()<UITextFieldDelegate>
{
    DataBlock _dataBlock;
}
@property (weak, nonatomic) IBOutlet UIButton *didRegistButton;
@property (weak, nonatomic) IBOutlet UIImageView *passwordTextBgImageView;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIImageView *repasswordTextBgImageView;
@property (weak, nonatomic) IBOutlet UITextField *repasswordTextField;
@property (weak, nonatomic) IBOutlet UIImageView *accountTextBgImageView;
@property (weak, nonatomic) IBOutlet UITextField *accountTextField;

@end

@implementation RegistViewController

- (void)initDataBlock:(DataBlock)dataBlock {
        _dataBlock = [dataBlock copy];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _accountTextField.delegate = self;
    _passwordTextField.delegate = self;
    _repasswordTextField.delegate = self;
    
    UIImage *inputBgImage = [_accountTextBgImageView.image resizableImageWithCapInsets:UIEdgeInsetsMake(12, 22, 12, 22) resizingMode:UIImageResizingModeStretch];
    [_accountTextBgImageView setImage:inputBgImage];
    [_passwordTextBgImageView setImage:inputBgImage];
    [_repasswordTextBgImageView setImage:inputBgImage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)didRegistButtonAction:(id)sender {
    [_didRegistButton setEnabled:NO];
    if (_dataBlock) {
        _dataBlock(_accountTextField.text, _passwordTextField.text);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (_accountTextField == textField) {
        [_passwordTextField becomeFirstResponder];
    } else if (_passwordTextField == textField) {
        [_repasswordTextField  becomeFirstResponder];
    } else if (_repasswordTextField == textField) {
        [textField resignFirstResponder];
    }
    return NO;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
